package com.zzh.lib.bar.extension

import android.content.Context
import android.os.Build
import android.util.DisplayMetrics
import android.view.WindowInsets
import android.view.WindowManager

internal fun Context.commonNavigationBarExist(): Boolean {
    val wm = getSystemService(Context.WINDOW_SERVICE) as WindowManager

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
        val d = wm.defaultDisplay
        val realDisplayMetrics = DisplayMetrics()

        d.getRealMetrics(realDisplayMetrics)

        val realHeight = realDisplayMetrics.heightPixels
        val realWidth = realDisplayMetrics.widthPixels

        val displayMetrics = DisplayMetrics()
        d.getMetrics(displayMetrics)

        val displayHeight = displayMetrics.heightPixels
        val displayWidth = displayMetrics.widthPixels

        return realWidth - displayWidth > 0 || realHeight - displayHeight > 0
    } else {
        val systemBar =
            wm.currentWindowMetrics.windowInsets.getInsets(WindowInsets.Type.systemBars())
        return systemBar.bottom > 0
    }
}